﻿import QtQuick 2.15
import QtQuick.Controls 2.15

Popup{
    width: 900
    height: 500
    anchors.centerIn: parent
    background: Rectangle{
        color: "gold"
        border.width: 5
        border.color: "#f0f8ff"
    }
    closePolicy: Popup.NoAutoClose

    Item{
        id:popupBackGround
        anchors.fill: parent
    }

    Rectangle{
        anchors.fill: popupBackGround
        color: "gold"

        Text{
            anchors.centerIn: parent
            font.pixelSize: 100
            font.bold: true
            color: "red"
            text: zeroLocationFailed ? qsTr("位置清零失败！") :
                    servoReady ? qsTr("伺服未准备好！") :
                    readLocationFailed ? qsTr("读取定位失败！") :
                    readLocationOver ? qsTr("读取定位完成！") :
                    forbidRun_NotFindZero ? qsTr("未找零禁止运行！"):
                    forbidLeftRun ? qsTr("禁止左行！") :
                    forbidRightRun ? qsTr("禁止右行！") :
                    currentLocationEqualLocation ? qsTr("当前位置等于"+"\n"+"  定位位置！") :
                    notChooseMechine ? qsTr("未选择电机！") :
                    workingForbidImpact ? qsTr("工作中禁止压紧！") :
                    sawErrForbidImpact ? qsTr("锯片后位信号异常"+"\n"+" 禁止压料动作！") :
                    sawNotRunForbidOut ? qsTr("压料气缸未压紧"+"\n"+" 禁止锯片出锯！") :
                    currentSectionesWorked ? qsTr("当前段数已加工完!"):
                    notImpactForbidOut ? qsTr("未压紧禁止出锯！") :
                    currentLocationForbidOut ? qsTr("当前位置禁止出锯！") :
                                          // autoPrintRun ? true :
                    setExtraShortLessCDLC ? qsTr("设定超短小于超短料长！") :
                    sawInPlacesSignalErr ? qsTr("锯片到位信号异常！") :
                    locationZeroOver ? qsTr("位置清零完成！") :
                    forbidRightMechineMove ? qsTr("禁止右机头移动！") :
                    extraLongLocation ? qsTr("超长定位！") :
                    changeSawMethod ? qsTr("切换锯方式！") :
                    errCorrected ? qsTr("错误修正完成！") :
                    forbid_45NB ? qsTr("禁止45度内摆！") :
                    extraShortOrigin ? qsTr("超短复位！") :
                    cleanBatteryWarning ? qsTr("清除电池报警！") :
                    cleanBatteryDone ? qsTr("清除电池报警完成！") :
                    q_TL_Err ? qsTr("前托料异常！") :
                    z_TL_Err ? qsTr("中托料异常！") :
                    h_TL_Err ? qsTr("后托料异常！") :
                                 qsTr("")
        }

    }



    Rectangle{
        width: 200
        height: 80
        anchors.horizontalCenter: popupBackGround.horizontalCenter
        anchors.bottom: popupBackGround.bottom
        anchors.bottomMargin: 10
        color: "#006cee"
        radius: 10
        border.width: 1
        border.color: "#f0f8ff"


        Text{
            anchors.centerIn: parent
            font.pixelSize: 30
            font.bold: true
            text: qsTr("关  闭")
        }

        MouseArea{
            anchors.fill: parent

            onPressed: {
                parent.color = "#ff3606"
            }

            onReleased: {

                parent.color = "#006cee"

                if(zeroLocationFailed)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("52","0")
                }
                else if(servoReady)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("56","0")
                }
                else if(readLocationFailed)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("57","0")
                }
                else if(readLocationOver)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("58","0")
                }
                else if(forbidRun_NotFindZero)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("59","0")
                }
                else if(forbidLeftRun)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("42","0")
                }
                else if(forbidRightRun)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("43","0")
                }
                else if(currentLocationEqualLocation)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("47","0")
                }
                else if(notChooseMechine)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("64","0")
                }
                else if(workingForbidImpact)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("68","0")
                }
                else if(sawErrForbidImpact)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("69","0")
                }
                else if(currentSectionesWorked)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("73","0")
                }
                else if(sawNotRunForbidOut)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("76","0")
                }
                else if(notImpactForbidOut)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("77","0")
                }
                else if(currentLocationForbidOut)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("80","0")
                }
                // else if(autoPrintRun)
                // {
                //     Cpp_Connect.write_modbus_rtu_Coils("135","0")
                // }
                else if(setExtraShortLessCDLC)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("134","0")
                }
                else if(sawInPlacesSignalErr)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("137","0")
                }
                else if(locationZeroOver)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("152","0")
                }
                else if(forbidRightMechineMove)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("159","0")
                }
                else if(extraLongLocation)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("149","0")
                }
                else if(changeSawMethod)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("164","0")
                }
                else if(errCorrected)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("170","0")
                }
                else if(forbid_45NB)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("153","0")
                }
                else if(extraShortOrigin)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("143","0")
                }
                else if(cleanBatteryWarning)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("196","0")
                }
                else if(cleanBatteryDone)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("197","0")
                }
                else if(q_TL_Err)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("250","0")
                }
                else if(z_TL_Err)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("251","0")
                }
                else if(h_TL_Err)
                {
                    Cpp_Connect.write_modbus_rtu_Coils("252","0")
                }

            }


        }

    }


}

